import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:lazy_load_indexed_stack/lazy_load_indexed_stack.dart';

import '/app/pages/file/folder_list_page.dart';
import '/app/pages/home/home_page.dart';
import '/app/pages/settings/settings_page.dart';
import '/app/routes/app_pages.dart';
import 'app_controller.dart';
import 'themes/theme_controller.dart';

class AppPage extends GetView<AppController> {
  final ThemeController themeController = Get.find();
  final AppController appController = Get.put(AppController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // backgroundColor: Theme.of(context).appBarTheme.backgroundColor,
        title: Text(
          'Snail Player',
          style: TextStyle(
            // color: Color(0xff191d31),
            fontSize: 20,
            fontFamily: "Outfit",
            fontWeight: FontWeight.w600,
          ),
        ),
        actions: [
          IconButton(
            icon: Icon(Icons.search),
            onPressed: () => Get.toNamed('/search'), // 点击时导航到搜索页面
          ),
          IconButton(
            icon: Icon(Icons.brightness_6),
            onPressed: themeController.toggleTheme,
          ),
          IconButton(
            icon: Icon(Icons.web_asset),
            onPressed: () => Get.toNamed(AppPages.webView), // 点击时导航到搜索页面
          ),
          IconButton(
            icon: Icon(Icons.audio_file),
            onPressed: () => Get.toNamed(AppPages.SETTINGS),
          ),
        ],
      ),
      body: Obx(() => LazyLoadIndexedStack(
            index: appController.currentIndex.value,
            children: [
              // 设置自动上下滑屏操作
              SingleChildScrollView(
                child: HomePage(),
              ),
              VideoFolderListPage(),
              SingleChildScrollView(
                child: SettingsPage(),
              ),
            ],
          )),
      bottomNavigationBar: Obx(
        () => BottomNavigationBar(
          currentIndex: appController.currentIndex.value,
          selectedFontSize: 10,
          unselectedFontSize: 8,
          onTap: (index) {
            appController.changeNavIndex(index);
          },
          items: const [
            BottomNavigationBarItem(
              icon: Icon(Icons.home_outlined),
              label: '首页',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.drive_file_move_outlined),
              label: '文件夹',
            ),
            // BottomNavigationBarItem(
            //   icon: Icon(Icons.open_in_browser_sharp),
            //   label: '浏览器',
            // ),
            BottomNavigationBarItem(
              icon: Icon(Icons.settings_outlined),
              label: '设置',
            ),
          ],
        ),
      ),
    );
  }
}
